package com.shelpe.services.sinbad.entity.jpa.vo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Convert;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.sinbad.entity.jpa.Campaign.AreaConverter;
import com.shelpe.services.sinbad.entity.jpa.Campaign.ScheduleConverter;
import com.shelpe.services.sinbad.entity.jpa.Campaign.ScheduleObject;
import com.shelpe.services.sinbad.controller.LogDto.LogNoteable;
import com.shelpe.services.sinbad.entity.jpa.DriveType;
import com.shelpe.services.sinbad.entity.jpa.OnlineStatus;
import com.shelpe.services.sinbad.service.utils.EntityUtils.DriveTypeConverter;
import com.shelpe.services.sinbad.service.utils.EntityUtils.OnlineStatusConverter;

import lombok.Data;

@Data
@JsonInclude(Include.NON_NULL)
public class CampaignVo implements LogNoteable {
	@JsonProperty("note_in")
	private boolean noteIn = true;

	@JsonProperty("campaign_id")
	private Long autoID;
	@JsonProperty("user_id")
	private Long userID;
	private String nick;
	@JsonProperty("old_title")
	private String oldTitle;
	@JsonProperty("new_title")
	private String newTitle;
	@JsonProperty("old_budget")
	private int oldBudget;
	@JsonProperty("new_budget")
	private int newBudget;
	@JsonProperty("online_status")
	@Convert(converter = OnlineStatusConverter.class)
	private OnlineStatus onlineStatus;
	@JsonProperty("settle_status")
	@Convert(converter = OnlineStatusConverter.class)
	private OnlineStatus settleStatus;

	@JsonProperty("create_time")
	@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd")
	private Date createTime;
	@JsonProperty("modified_time")
	@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd")
	private Date modifiedTime;

	@Convert(converter = ScheduleConverter.class)
	private ScheduleObject schedule;
	@Convert(converter = AreaConverter.class)
	@JsonProperty("add_area")
	private Area addArea;

	@JsonProperty("less_area")
	@Convert(converter = AreaConverter.class)
	private Area lessArea;

	@JsonProperty("add_old_platform")
	private ConvertPlatformVo addPlatform;
	@JsonProperty("less_new_platform")
	private ConvertPlatformVo lessPlatform;

	@Convert(converter = DriveTypeConverter.class)
	@JsonProperty("old_auto_type")
	private DriveType oldAutoType;
	@Convert(converter = DriveTypeConverter.class)
	@JsonProperty("new_auto_type")
	private DriveType newAutoType;
	@JsonProperty("semiauto_message")
	private String semiautoMessage;
	@JsonProperty("old_campaign_limit")
	private int oldLimit;
	@JsonProperty("new_campaign_limit")
	private int newLimit;

	@Data
	public static class Area {
		private boolean asAll;
		private List<Integer> nums;

		public void addArea(int num) {
			if (this.nums == null) {
				this.nums = new ArrayList<Integer>();
			}
			this.nums.add(num);
		}
	}
}